package storeSortingWeighRecord

import (
	"insighttracking/common/utils"
	"net/http"

	"github.com/zeromicro/go-zero/rest/httpx"
	"insighttracking/apps/sorting/internal/logic/storeSortingWeighRecord"
	"insighttracking/apps/sorting/internal/svc"
	"insighttracking/apps/sorting/internal/types"
)

func CreateStoreSortingWeighRecordApiHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		var req types.CreateStoreSortingWeighRecordReq
		if err := httpx.Parse(r, &req); err != nil {
			httpx.ErrorCtx(r.Context(), w, err)
			return
		}
		// 数据验证
		if validateErr := utils.Validate(&req); validateErr != nil {
			httpx.ErrorCtx(r.Context(), w, validateErr)
			return
		}
		l := storeSortingWeighRecord.NewCreateStoreSortingWeighRecordApiLogic(r.Context(), svcCtx, r)
		resp, err := l.CreateStoreSortingWeighRecordApi(&req)
		if err != nil {
			httpx.ErrorCtx(r.Context(), w, err)
		} else {
			httpx.OkJsonCtx(r.Context(), w, resp)
		}
	}
}
